package com.project.utils;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.io.File;
import java.io.FileWriter;

/**
 * @author Sweey Zhang
 * @description
 * @date 2021/9/9 14:48
 */
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class ClearSchedule {
    /**
     * @Description 设置每天0点执行一次
     **/
    @Scheduled(cron = "0 0 0 * * ?")
    private void process() {
        String project_path = System.getProperty("user.dir");
        String bayonet_file_path = project_path + File.separator + "bayonet.txt";
        File file = new File(bayonet_file_path);
        if (file.exists() && file.length() != 0) {
            try (FileWriter fw = new FileWriter(file)) {
                fw.write("");
                fw.flush();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
